﻿using System;
using ApplicationGenerator.Forms.WebControls;
using ApplicationGenerator.CommonWeb;

namespace ApplicationGenerator.Forms.Actions
{
    /// <summary>
    /// Akcja cofnij. Ma zastosowanie poza procesem
    /// </summary>
    [Serializable]
    public class PrevAction : ActionBase
    {
        #region Overrides
        /// <summary>
        /// Wykonuje akcję
        /// </summary>
        /// <param name="buttonControl">Kontrolka przycisku powiązanego z akcją</param>
        /// <param name="formWebControl">Kontrolka formularza</param>
        public override void Execute(ButtonControl buttonControl, FormWebControl formWebControl)
        {
            WebPagesHistory webPagesHistory = formWebControl.Page.Session[WebPagesHistory.HistorySessionKeyName] as WebPagesHistory;
            if (webPagesHistory == null)
            {
                return;
            }

            formWebControl.Page.Response.Redirect(webPagesHistory.GetPreviousPage(formWebControl.Page.Request.Url.PathAndQuery, formWebControl.Page.Request.QueryString));

        }
        #endregion
    }
}
